<?php

class Economy_IndexController extends Zend_Controller_Action {

    public function init() {
        $auth = Zend_Auth::getInstance();

        if (!$auth->hasIdentity()) {
            $this->_redirect('/user/login');
        }
        $view = new Zend_View();
        $view->headTitle(' > Economy > Dashboard');
        $this->view->userDetail = $auth->getIdentity();
    }

    public function indexAction() {
        $switchModel = new Application_Model_SwitchModel();

        $cabinetModel = new Application_Model_CabinetModel();
        $cabinets = $cabinetModel->fetchAll("status = 'active'");
        $form = new Application_Form_economy_TidsForm($cabinets);

        $switches = $switchModel->getSwitchesProgeressForEconomy($this->_request, $cabinets[0]->id);

        $this->view->form = $form;
        $this->view->paginator = $switches;
        $this->view->cabinetId = $cabinets[0]->id;
    }

    public function listAction() {
        $this->_helper->layout->disableLayout();
        $switchModel = new Application_Model_SwitchModel();
        $switches = $switchModel->getSwitchesProgeressForEconomy($this->_request, $this->_request->getParam('id', 1));
        $this->view->paginator = $switches;
        $this->view->cabinetId = $this->_request->getParam('id', 1);
    }

    public function switchAction() {
        $this->_helper->layout->disableLayout();
        $houseModel = new Application_Model_HouseModel();
        $houses = $houseModel->getHousesProgeressForEconomy($this->_request, $this->_request->getParam('id', 1));
        $this->view->paginator = $houses;
        $this->view->switchId = $this->_request->getParam('id', 1);
    }
}